package com.mo.sys.web.exception;

import com.mo.sys.web.pojo.LogJsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice   //@ControllerAdvice+@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public LogJsonResult dohanleRunTimeException(
            RuntimeException e) {
        e.printStackTrace();
        log.error("exception{}", e.getMessage());
        return new LogJsonResult(e);
    }

    @ExceptionHandler(NumberFormatException.class)
    public LogJsonResult dohanleNumberFormatException(
            NumberFormatException e) {
        e.printStackTrace();
        log.error("exception{}", "你传参不匹配");
/*
        LogJsonResult r=new LogJsonResult();
        r.setState(0);
        r.setMessage("你传参不匹配");
        return r;
*/
        return new LogJsonResult(0,"你传参不匹配");
    }
}